using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using System.Net.NetworkInformation;
namespace LyonMag
{
    public partial class CinemaDetail : PhoneApplicationPage
    {
        string id = string.Empty;
        private App app = App.Current as App;
        string synposis = string.Empty;
        string tirle = string.Empty;
        public CinemaDetail()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {

                NavigationContext.QueryString.TryGetValue("id",out id);
                for (int i = 0; i < app.lst_Cinema_comment.Count(); i++)
                {
                    if (id == app.lst_Cinema_comment[i].Id)
                    {
                        txtActors.Text = app.lst_Cinema_comment[i].Category;
                        txtDate.Text = app.lst_Cinema_comment[i].Date;
                        txtDuration.Text = app.lst_Cinema_comment[i].Category;
                        txtSynop.Text = app.lst_Cinema_comment[i].Fulltext;
                        System.Windows.Media.Imaging.BitmapImage nit = new System.Windows.Media.Imaging.BitmapImage();
                        nit.UriSource = new Uri(app.lst_Cinema_comment[i].AppImage);
                        img.Source = nit;
                        txtDistri.Text = app.lst_Cinema_comment[i].Distributeur;
                        txtDuration.Text = app.lst_Cinema_comment[i].Duree;
                        txtActors.Text = app.lst_Cinema_comment[i].Acteur;
                        txtTitle.Text = app.lst_Cinema_comment[i].Title;
                        txtGenre.Text = app.lst_Cinema_comment[i].Genres;
                        txtRea.Text = app.lst_Cinema_comment[i].Realisateur;
                        synposis = app.lst_Cinema_comment[i].Fulltext;
                        tirle = app.lst_Cinema_comment[i].Title;
                    }
                }
            }
            catch(Exception ex)
            {
                ex.Message.ToString();

                if (NetworkInterface.GetIsNetworkAvailable() == true)
                {
                    // MessageBox.Show(NetworkInterface.GetIsNetworkAvailable().ToString());
                }
                else
                {
                    MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                }
            }

        }

        private void btnTheatres_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Theatre.xaml?id=" + id, UriKind.RelativeOrAbsolute));
        }

        private void txtTitle_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
        {

        }

        private void imgShare_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                ShareLinkTask share = new ShareLinkTask();
                share.LinkUri = new Uri("http://www.lyonmag.com",UriKind.Absolute);
                share.Title = tirle;
                share.Message = synposis;
                share.Show();
            }
            catch(Exception ex)
            {
                ex.Message.ToString();
            }
        }
    }
}